import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.Timer;

public class GamePiece {

	//Images for different GamePieces
	public static final ImageIcon reboundRumblePiece = new ImageIcon("R_RGamepiece.png");
	public static final ImageIcon logomotionPiece = new ImageIcon("LGamepiece.png");
	Timer timer;

	private Robot owner;
	//We can modify the sizes later.
	//position is the center point
	private int X_SIZE = 10, Y_SIZE = 10;
	private Point position;
	private boolean carried = false, targeted = false;	

	public GamePiece(Point position, boolean carried){
		this.position = position;
		this.carried = carried;		
	}

	//Takes in a field type and array of GamePieces
	//Modifies with necessary GamePieces for user selected game
	public static void generateGamePieceList(int fieldType, ArrayList<GamePiece> gamePieceList){

		if(fieldType == Field.REBOUND_RUMBLE){
			gamePieceList.add(new GamePiece(new Point(600,150), false));
			gamePieceList.add(new GamePiece(new Point(600,200), false));
			gamePieceList.add(new GamePiece(new Point(600,250), false));
			gamePieceList.add(new GamePiece(new Point(600,300), false));
			gamePieceList.add(new GamePiece(new Point(600,350), false));
			gamePieceList.add(new GamePiece(new Point(600,400), false));
		}
		if(fieldType == Field.LOGOMOTION){
			gamePieceList.add(new GamePiece(new Point(200,275), false));
			gamePieceList.add(new GamePiece(new Point(200,325), false));
			gamePieceList.add(new GamePiece(new Point(600,250), false));
			gamePieceList.add(new GamePiece(new Point(600,300), false));
			gamePieceList.add(new GamePiece(new Point(600,350), false));
			gamePieceList.add(new GamePiece(new Point(1000,275), false));
			gamePieceList.add(new GamePiece(new Point(1000,325), false));
		}
	}

	//Respawns GamePieces after missing to a specified area for each alliance
	//No physics here
	public void bounce() {
		position = new Point(Robot.randomizer.nextInt(1000)+100, Robot.randomizer.nextInt(400)+100);
	}

	//Draws GamePieces if they are not already being carried on the field
	//If they are being carried, they will just be drawn in their owner robot
	public void drawGamePiece(Graphics page, int fieldtype){
		if(fieldtype == Field.REBOUND_RUMBLE){
			if(!carried){
				reboundRumblePiece.paintIcon(null,page,
						position.x-X_SIZE/2,
						position.y-Y_SIZE/2);
			}
			if(carried){
				reboundRumblePiece.paintIcon(null, page,  this.owner.getXPosition(), this.owner.getYPosition());
			}
		}
		if(fieldtype == Field.LOGOMOTION){
			if(!carried){
				logomotionPiece.paintIcon(null,page,
						position.x-X_SIZE/2,
						position.y-Y_SIZE/2);
			}
			if(carried){
				logomotionPiece.paintIcon(null, page,  this.owner.getXPosition(), this.owner.getYPosition());
			}
		}
	}

//	Getters and Setters
	public int getXPosition(){
		return position.x;
	}

	public int getYPosition(){
		return position.y;
	}

	public Point getPostion(){
		return position;
	}

	public void setOwner(Robot owner){
		this.owner = owner;
		carried = true;
	}

	public Robot getOwner(){
		return owner;
	}

	public Point getPosition() {
		return position;
	}

	public void setPosition(Point position) {
		this.position = position;
	}

	public void setCarried(boolean carried){
		this.carried = carried;
	}

	public boolean isCarried(){
		return carried;
	}

	public void setTargeted(boolean targeted){
		this.targeted = targeted;
	}

	public boolean isTargeted(){
		return targeted;
	}
}
